package order_pay_mode

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type OrderPayMode int

const (
	Default  OrderPayMode = -1
	Redirect OrderPayMode = iota
	Form
)

func (e OrderPayMode) Code() int32 {
	return int32(e)
}

func (e OrderPayMode) Des() string {
	return enums.BE(e).Des
}

func (e OrderPayMode) Enum() string {
	return enums.BE(e).Enum
}

func (e OrderPayMode) Val() int {
	return int(e)
}

func (e *OrderPayMode) UnmarshalJSON(value []byte) error {
	*e = OrderPayMode(enums.UnmarshalEnum(value))
	return nil
}

func (e OrderPayMode) MarshalJSON() ([]byte, error) {
	switch e {
	case Default:
		return enums.JsonObj(int(e), "Default", "未知")
	case Redirect:
		return enums.JsonObj(int(e), "Redirect", "跳转")
	case Form:
		return enums.JsonObj(int(e), "Form", "表单")
	}
	return []byte(strconv.Itoa(int(e))), nil
}
